var express = require('express');
var bodyParser = require("body-parser");
var cookieParser = require("cookie-parser");
var session = require("express-session");
var favicon = require("serve-favicon");
var jade = require("jade");
var logger = require("morgan");

var routes = require("./routes");
var ui = require("./routes/ui");
var pages = require("./routes/pages");
var ajax = require("./routes/ajax");

var app = express();

app.set('view engine', 'jade');
app.set('views', __dirname + '/view');
app.use(express.static(__dirname + '/bower_components'));
app.use(express.static(__dirname + '/public'));
app.use(logger("dev"));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(session({
	secret: "sklbss",
	saveUninitialized: true,
	resave: false
}));
app.use(favicon(__dirname + '/public/favicon.ico'));

// pages
app.get('/', pages.index);
app.post('/', pages.login);
app.get('/testing', pages.testing);

// ajax
app.get('/logout', ajax.logout);

// testing system proxy
app.all('/proxypath/*', routes.proxy);

app.listen(3000);